package com.midea.leetcode;

public class transStock {
//    public static void main(String[] args) {
//        int solution = solution(new int[]{7,1,5,3,6,8,-3,0});
//        System.out.println(solution);
//    }
//    public static int solution(int[] array){
//        int min = Integer.MAX_VALUE;
//        int max = 0;
//        for (int i : array) {
//            min = Integer.min(min,i);
//            max = Integer.max(max,i - min);
//        }
//        return max;
//    }

    public static void main(String[] args) {
        System.out.println(solution(new int[]{7,1,5,3,10,4,9}));
    }
    public static int solution(int array[]){
        int lirun = 0;
        int result = 0;
        int b = 0;
        for(int i =0;i <= array.length - 2; i++){
            lirun = array[i+1] - array[i];
            result += lirun;
            if(result < 0){
                result = 0;
            }
            if (result > b) {
                b = result;
            }
        }
        return b;
    }
}
